﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DFGK.Service
{
    public class EMPModelService : BaseService, IEMPModelService
    {
        private readonly IEMPModelRepository _repository;
        private readonly IUnitOfWork _unitOfWork;
        public EMPModelService(IMapper mapper, IEMPModelRepository _repository, IUnitOfWork unitOfWork) : base(mapper)
        {
            this._repository = _repository;
            _unitOfWork = unitOfWork;
        }

        public bool AddEMPMsg(EMPModel model)
        {
            _repository.AddEntity(model);
            return _unitOfWork.SaveChangesEntity();
        }

        public bool DelEMPMsg(long id)
        {
            var empMsg = _repository.QueryEntityById(id);
            if (empMsg != null)
            {
                _repository.DelEntity(empMsg);
                return _unitOfWork.SaveChangesEntity();
            }
            return false;
        }

        public List<EMPModel> GetAllEMPMsg(int? paymentID, int pageIndex, int pageSize, out int totalCount)
        {
            var empList = _repository.GetEntityAlls();
            if (paymentID != null && paymentID != 0)
            {
                empList = empList.Where(c => c.PaymentID == paymentID);
            }
            var list = _repository.GetEntityAlls(empList, pageIndex, pageSize, out totalCount, x => x.CreateDate, false);
            return list.ToList();
        }

        public EMPModel GetEMPMsgById(long id)
        {
            return _repository.QueryEntityById(id);
        }

        public List<EMPModel> GetAllEMP()
        {
            var list = _repository.GetEntityAlls();
            return list.ToList();
        }

        public bool UpdEMPMsg(EMPModel model)
        {
            var aobj = _repository.QueryIsEntityWhere(x => x.Id == model.Id);
            if (aobj == null)
            {
                return false;
            }
            _repository.UpdEntity(aobj);
            return _unitOfWork.SaveChangesEntity();
        }
    }
}
